using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spinning.Spinning.ScrollLayout;
using Spinning.Spinning.Unitity;
using Spinning.Spinning.Entity;
using Microsoft.Xna.Framework;

namespace Spinning.Spinning.Scenes.ProcessScene.TopMembers
{
    class ScrollMenu : ScrollLayoutScene
    {
        Sprite line_2;
        Sprite line_3;
        float lineLengh;

        public ScrollMenu()
        {
            ZIndex = Constants.ui;
            Size = new Microsoft.Xna.Framework.Vector2(405, 286);
        }

        public override void OnLoad()
        {
            base.OnLoad();

            line_2 = new Sprite();
            if (Size.Y > 300) line_2.textureName = "item_store/line04";
            else line_2.textureName = "item_store/line_2";
            line_2.OnLoad();
            line_2.ZIndex = Constants.ui;
            Attach(line_2);
            line_2.Origin = new Vector2(.5f);
            line_2.Position = new Vector2(405 - 25, Size.Y / 2);

            line_3 = new Sprite();
            line_3.textureName = "item_store/line_3";
            line_3.OnLoad();
            line_3.ZIndex = Constants.ui;
            Attach(line_3);
            line_3.Origin = new Vector2(.5f);
            line_3.Position = new Vector2(405 - 25, Size.Y / 2);

            lineLengh = Size.Y - 50;

        }

        public override void AddItem(ScrollLayoutElement item)
        {
            if (_items.Count > 0)
            {
                AddLine();
            }
            base.AddItem(item);
        }

        void AddLine()
        {
            ScrollLayoutElementSpace sss = new ScrollLayoutElementSpace();
            sss.OnLoad();
            Attach(sss);
            _items.Add(sss);
        }

        protected override void DrawSelf(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, Microsoft.Xna.Framework.GameTime gameTime)
        {
            base.DrawSelf(spriteBatch, gameTime);

            float l2s = lineLengh / line_2.SpriteSize.Y;
            float l3s = Size.Y * lineLengh / (AllItemHeight + SafeSpace);

            line_2.Scale = new Vector2(1, l2s);
            line_3.Scale = new Vector2(1, l3s);

            float transY = (-_scrollPositionY) + Size.Y / 2;

            float y = transY * lineLengh / (AllItemHeight + SafeSpace);

            line_3.Position = new Vector2(line_3.Position.X, y + 50);

            line_2.Visable = canScroll();
            line_3.Visable = canScroll();

        }

    }
}
